package com.atguigu.bean;

import java.math.BigDecimal;

public class CartItem {
    //书的信息
    private  Book book;
    //数量
    private int count;
    //金额
    private double amount;

    public CartItem() {
    }
    //有参构造器（但是没有金额 金额通过计算得到只提供一个获得的方法）
    public CartItem(Book book, int count) {
        this.book = book;
        this.count = count;
    }

    public double getAmount() {
        BigDecimal price = new BigDecimal(this.book.getPrice() + "");
        BigDecimal count = new BigDecimal(this.count + "");
        return price.multiply(count).doubleValue();
    }

    public Book getBook() {
        return book;
    }

    public void setBook(Book book) {
        this.book = book;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    @Override
    public String toString() {
        return "CartItem{" +
                "book=" + book +
                ", count=" + count +
                '}';
    }
}
